package customer.zspt.cn.customer.Adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import java.util.List;

import customer.zspt.cn.customer.R;
import customer.zspt.cn.customer.bean.OrderMsgDao;
import customer.zspt.cn.customer.Widget.OrderMsgItem;

/**
 * Created by Administrator on 2018/7/12 0012.
 */

public class OrderAdapter extends PagerAdapter {
   private String[] order_title;
    private Context context;
    private  List<List<OrderMsgDao.OrderMsg>> all;
   public OrderAdapter(String[] order_title, Context context, List<List<OrderMsgDao.OrderMsg>> all)
   {
       this.order_title = order_title;
       this.context = context;
       this.all = all;
   }

//    @Override
//    public CharSequence getPageTitle(int position) {
//        return order_title[position];
//    }

    @Override
    public int getCount() {
        return order_title.length;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
         View view = View.inflate(context, R.layout.order_vp_item,null);
        LinearLayout order_ll = view.findViewById(R.id.order_ll);
        List<OrderMsgDao.OrderMsg> orderMsgs = all.get(position);
        for(int i=0;i<orderMsgs.size();i++)
        {
            OrderMsgItem item = new OrderMsgItem(context);
            item.setOrderTitle(orderMsgs.get(i).orderTitle);
            item.setDataIndex(position,i);
            item.setOnClickListener(mClickListener);
            order_ll.addView(item);
        }
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
    private View.OnClickListener mClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
          OrderMsgItem item = (OrderMsgItem) view;
            if(listener!=null)
            {
                listener.onclick(all.get(item.type).get(item.type_index).orderId+"",
                        all.get(item.type).get(item.type_index).toString());
            }

        }
    };
    public  IonclickCallBack listener;
    public interface IonclickCallBack
    {
        void onclick(String orderId,String ordercontent);
    }

    public void OnclickStartListener(IonclickCallBack listener)
    {
        this.listener = listener;
    }
}
